﻿using SinBiota.Model.Entities;

namespace SinBiota.Model.Persistence.NHibernateMappings
{
    public class OccurrenceMapping : BaseEntityMapping<Occurrence>
    {
        public OccurrenceMapping()
        {
            References(x => x.Project).Not.Nullable();
            References(x => x.Author).Not.Nullable();
            References(x => x.User);
            References(x => x.BibliographicalReference);
            Map(x => x.StartDate).Length(12);
            Map(x => x.EndDate).Length(12);
            References(x => x.Location);
            References(x => x.AquaticData);
            HasManyToMany(x => x.Ecosystems);
            Map(x => x.UncertainInformation);
            HasManyToMany(x => x.Habitats);
            HasManyToMany(x => x.MicroHabitats);
            References(x => x.Method);
            Map(x => x.FinalRemarks).Length(MAXCHAR);
            HasManyToMany(x => x.Keywords);
            HasMany(x => x.SpecimenList).Inverse().Cascade.AllDeleteOrphan();
            HasManyToMany(x => x.RelatedOccurrences).ParentKeyColumn("Occurrence1_Id").ChildKeyColumn("Occurrence2_Id").Table("OccurrenceToOccurrence");
            Map(x => x.OpenAccessDate).Length(12);
            Map(x => x.RecordDate).Length(12);
            Map(x => x.LastUpdateDate).Length(12);
        }
    }
}
